﻿using System;
using RedmineTypes = Redmine.Net.Api.Types;
using System.Collections.Generic;

namespace Redmine.Laptop.API.Models
{
    public class User 
    {
        public int UserID { get; set; }
        public string Login { get; set; }
        public string Password { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime? LastLoginDate { get; set; }
        public List<UserGroup> Groups { get; set; }

        public string UserName
        {
            get { return FirstName + " " + LastName; }
        }

        public static explicit operator RedmineTypes::User(User user)
        {
            return new RedmineTypes::User
                       {
                           Id = user.UserID,
                           CreatedOn = user.CreatedDate,
                           Email = user.Email,
                           FirstName = user.FirstName,
                           Groups = (user.Groups ?? new List<UserGroup>()).ConvertAll(ug => (RedmineTypes::UserGroup) ug),
                           LastLoginOn = user.LastLoginDate,
                           LastName = user.LastName,
                           Login = user.Login,
                           Password = user.Password
                       };
        }

        public static explicit operator User(RedmineTypes::User user)
        {
            return new User
                       {
                           CreatedDate = user.CreatedOn.Value,
                           Email = user.Email,
                           FirstName = user.FirstName,
                           LastLoginDate = user.LastLoginOn,
                           LastName = user.LastName,
                           Login = user.Login,
                           Password = user.Password,
                           UserID = user.Id,
                           Groups = (user.Groups ?? new List<RedmineTypes::UserGroup>()).ConvertAll(ug => (UserGroup)ug)
                       };
        }
    }
}
